﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using CoreEx.Common.Data;
using CoreEx.Database.Metadata;
using CoreEx.MicroMapper;
using CoreEx.Common.Extensions;
using LinFu.IoC.Interfaces;

namespace CoreEx.Common.Repository
{
    //public interface IRelationMapper
    //{
    //    void MapRelations(IDictionary<Type, ITable> tables, IEnumerable<IEnumerable> sourceLists);
    //}


    public interface IMappingTarget
    {
        /// <summary>
        /// Gets the table that was used to map the <see cref="List"/>
        /// </summary>
        ITable Table { get; }

        /// <summary>
        /// Gets a list properties that represent a relation to another mapping target (Child or parent relations)  
        /// </summary>
        IEnumerable<PropertyInfo> Properties { get;}

        /// <summary>
        /// Gets an <see cref="IEnumerable{T}"/> that represents the result of the mapping process.
        /// </summary>
        IEnumerable List { get; }

               
        ITypeMappingInfo TypeMappingInfo { get; set; }
    }


    




    //public interface IRelationMapper<T> : IMicroMapper<IMappingTarget, IList<T>>
    //{

    //}

    


    //public class RelationMapper<T> : MicroMapper<IMappingTarget, IList<T>>, IRelationMapper<T>
    //{
    //    private IEnumerable<IMappingTarget> _mappingTargets;
        
       
        
    //    public override void Initialize(IServiceContainer source)
    //    {
    //        TargetFactory = mappingTarget => (IList<T>)mappingTarget.List;

    //        Explicit((target, ts) =>
    //                     {
    //                         //target.TypeMappingInfo.ColumnMappings.Where(c => c.Value.RelationType == )
                             
    //                         //target.List.AsQueryable().Where()
    //                     });
            
    //        base.Initialize(source);
    //    }
    //}


    public interface IRelationMapper
    {
        void MapRelations(IDictionary<Type,ITable> mappingTargets); 
    }


    public class RelationMapper : IRelationMapper
    {
        public void MapRelations(IDictionary<Type, ITable> mappingTargets)
        {
            throw new NotImplementedException();
        }
    }
    



}    
